<?php

namespace Home\Controller;

use Home\Base\Util;
use Think\Controller;

/**
 * @desc 常用功能
 * @author 张云江
 */
class UserCenterController extends InitController
{
    /**
     * 欢迎页面
     */
    public function userlist()
    {

        $application_id = $_GET['application_id'];

        if (empty($application_id)) {
            $application_id = 0;
        }

        $MemOrder_User_info = new \Mem\MemOrder_User_info();
        $page_size = 100;

        $MemOrder_Application_info = new \Mem\MemOrder_Application_info();
        $applicatonList = $MemOrder_Application_info->getDataWithAll();
        $this->assign("applicationList", $applicatonList);

        $total = $MemOrder_User_info->getCountDataWithAll($application_id);
        $pageObj = Util::getPageObject($total, $page_size); //加入分页
        $mempage = $pageObj["mempage"];

        $dataList = $MemOrder_User_info->getDataWithAll($application_id, $mempage);
        $newdataList = array();
        foreach ($dataList as $val) {
            if ($val['vip'] == 1) {
                $val['vip_show'] = '会员';
            } else {
                $val['vip_show'] = '非会员';
            }
            $device_model = $val['device_model'];
            $device_model_arr = explode("-", $device_model);

            if (!empty($device_model_arr)) {
                $device_x = $device_model_arr[0];
                $device_all = C('APPLE_DEVICE_ALL');
                foreach ($device_all as $deVal) {
                    if (strcmp(array_keys($deVal)[0], $device_x) == 0) {
                        $val['device_model'] = array_values($deVal)[0] . '-' . $device_model_arr[1] . '-' . $device_model_arr[2];
                    }
                }
            }
            array_push($newdataList, $val);
        }
        $this->assign("dataList", $newdataList);
        $this->assign("application_id", $application_id);
        $pageshow = $pageObj["pageshow"];
        $this->assign("page", $pageshow);
        $this->assign("pageindex", $pageObj["mempage"]->getLimitIndex());

        $navPage = array(
            array("name" => "用户列表", "url" => ""),
        );
        $this->assign("navPage", $navPage);
        $this->assign("menuFlag", "userlist");
        $this->display();
    }
}
